package com.bawei.common.dailog

import android.content.Context
import android.content.DialogInterface
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.WindowManager
import android.widget.ImageView
import androidx.appcompat.app.AppCompatDialog
import com.bawei.common.R

/**
 * Author: Jason Zhang
 * Date: 2024/8/26
 * Desc: App版本更新弹窗
 */
class AppUpdateDialog: AppCompatDialog {

    constructor(context: Context): super(context)

    constructor(context: Context, theme: Int): super(context, theme)

    constructor(context: Context, cancelable: Boolean, cancelListener: DialogInterface.OnCancelListener): super(context, cancelable, cancelListener)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //1.设置布局
        setContentView(R.layout.app_update_layout)
        //2.设置取消事件
        findViewById<ImageView>(R.id.iv_update_close)?.setOnClickListener {
            cancel()
        }
        //修改样式
        var windowParams: WindowManager.LayoutParams = window?.attributes!!
        windowParams.apply {
            dimAmount = 0.3f //灰色区域暗度
            width = WindowManager.LayoutParams.MATCH_PARENT
            height = WindowManager.LayoutParams.MATCH_PARENT
        }
        window?.attributes = windowParams
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        //设置可以取消
        setCanceledOnTouchOutside(false)
        setCancelable(true)
    }




}